#include "Logger.h"

#include <stdarg.h>

using namespace BWAPI;

Logger::Logger()
{
}

Logger::Logger(std::string filename)
{
	logLevel = LogLevels::Info;
	logFile.open(filename.c_str(), ios::out | ios::app);
}

Logger::~Logger(void)
{
	logFile << "----------------" << endl;
	logFile.close();
}

void Logger::setLevel(LogLevels::Level _logLevel)
{
	logLevel = _logLevel;
}

void Logger::setGame(BWAPI::Game* _game)
{
	game = _game;
}

void Logger::log(LogLevels::Level lvl, std::string message)
{
	if (lvl>=logLevel)
	{
		logFile << message << endl;
		game->printf(message.c_str());
	}
}

void Logger::log(LogLevels::Level lvl, const char *format, ...)
{
	if (lvl>=logLevel)
	{
		va_list args;
		va_start(args, format);
		char buffer[1000];
		vsprintf(buffer, format, args);
		logFile << buffer << endl;
		game->printf(buffer);
	}
}